In [2]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
In [3]:
data = pd.DataFrame({
'Year': [2019, 2020, 2021, 2022, 2023],
'Sales': [150, 200, 250, 300, 400],
'Profit': [30, 50, 65, 80, 120]
})
data
Out[3]:
| Year | Sales | Profit | |
|---|---|---|---|
| 0 | 2019 | 150 | 30 |
| 1 | 2020 | 200 | 50 |
| 2 | 2021 | 250 | 65 |
| 3 | 2022 | 300 | 80 |
| 4 | 2023 | 400 | 120 |
In [4]:
plt.figure(figsize=(8,5))
plt.plot(data['Year'], data['Sales'], marker='o', color='green', label='Sales')
plt.plot(data['Year'], data['Profit'], marker='s', color='blue', label='Profit')
plt.title("Company Growth Over 5 Years", fontsize=16, fontweight='bold')
plt.xlabel("Year")
plt.ylabel("Value (in $1000s)")
plt.legend()
plt.grid(True)
plt.show()
In [5]:
sns.set_style("whitegrid")
plt.figure(figsize=(8,5))
sns.barplot(x='Year', y='Sales', data=data, palette='crest')
plt.title("Yearly Sales Comparison", fontsize=15, fontweight='bold')
plt.xlabel("Year")
plt.ylabel("Sales ($ in thousands)")
plt.show()
C:\Users\ABU SAYEED\AppData\Local\Temp\ipykernel_25524\3634998768.py:3: FutureWarning: Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect. sns.barplot(x='Year', y='Sales', data=data, palette='crest')
In [6]:
fig = px.line(data, x='Year', y=['Sales', 'Profit'],
title='Interactive Sales & Profit Trends',
markers=True)
fig.update_layout(title_font_size=22, font=dict(color='darkblue'))
fig.show()
In [7]:
labels = ['Sales', 'Profit']
values = [data['Sales'].sum(), data['Profit'].sum()]
fig = px.pie(names=labels, values=values, title='Sales vs Profit Share',
color_discrete_sequence=px.colors.sequential.RdBu)
fig.show()
In [8]:
fig, axs = plt.subplots(1, 3, figsize=(15, 5))
# Line
axs[0].plot(data['Year'], data['Sales'], color='blue', marker='o')
axs[0].set_title("Sales Trend")
# Bar
axs[1].bar(data['Year'], data['Profit'], color='orange')
axs[1].set_title("Profit by Year")
# Pie
axs[2].pie(values, labels=labels, autopct='%1.1f%%', colors=['skyblue','salmon'])
axs[2].set_title("Sales vs Profit Share")
plt.suptitle("Data Visualization Dashboard", fontsize=18, fontweight='bold')
plt.show()
In [ ]:
### Insights
- Sales and profits both show consistent growth from 2019 to 2023.
- Profit increased faster than sales, suggesting better margins.
- The pie chart shows sales contribute the major share to overall performance.